//水仙花数（自幂数）
public class test {
    public static void main(String[] args) {
        int i = 1;
        for(i = 1;i <= 9999;i++){
            int count = 0;
            int tmp = i;//取一个数来代替i的值
            while(tmp!= 0){
                //为了得到i为几位数
                count++;//先执行一次count++，count是为了计算i有几位数
                tmp = tmp / 10;
                //tmp=0,count=3(以i=123举例)
            }
            int sum = 0;
            tmp = i;
            while(tmp != 0){
                sum += Math.pow(tmp % 10,count);//tmp为了得到i的每一位数，count为次数
                tmp /= 10;
            }
            if(sum == i){
                System.out.println(count+"位的自幂数为"+i);
            }
        }
    }
    public static void main5(String[] args) {
     int i = 1;
     int f = 1;
     double sum = 0;
     for(i = 1;i <=100;i++){
         sum = sum + (1.0/i)*f;
         f = -f;
     }
        System.out.println(sum);
    }
    public static void main4(String[] args) {
        int year = 1000;
        for(;year <= 2000;year++) {
            if (year % 100 == 0) {
                //判断世纪闰年
                if (year % 400 == 0) {
                    System.out.print(year+" ");
                }
            } else {
                if (year % 4 == 0) {
                    System.out.print(year+" ");
                }

            }
        }
    }

    public static void main3(String[] args) {
        int n = 11;
        int i = 2;
        for(;i <=n-1;i++){
            if(n % i == 0){
                System.out.println("不是素数");
                break;
            }
            }
        if(i > n-1) {
            System.out.println(n+"是素数");
        }
    }
    public static void main2(String[] args) {
        int a = 18;
        int b = 12;
        int c = a % b;
        while (c != 0){
            a = b;
            b = c;
            c = a % b;
        }
        System.out.println(b);



    }
    public static void main1(String[] args) {
        int count = 0;
        for(int i = 0;i <= 100; i++){
            if(i%10 == 9){
                count ++;
            }
            if(i/10 == 9){
                count ++;
            }
        }
        System.out.println(count);
    }
}
